package com.library.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.library.common.base.ApiResult;
import com.library.common.entity.MyPage;
import com.library.entity.BookUserEntity;
import com.library.entity.RBookCar;
import com.library.entity.dto.BookCarDto;
import com.library.entity.vo.BookUserVo;
import com.library.entity.vo.UserVo;
import com.library.service.BookUserService;
import com.library.service.RBookCarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 图书购物车 前端控制器
 * </p>
 *
 * @author ccl
 * @since 2024-10-22
 */
@Slf4j
@RestController
@RequestMapping("/api/bookCar")
@Api(tags = "书购物车", value = "书购物车相关接口")
public class RBookCarController {

    @Resource
    private RBookCarService rBookCarService;

    @ApiOperation(value = "分页查询")
    @PostMapping("/queryPage")
    public MyPage<RBookCar> queryPage(@RequestBody BookCarDto bookCarDto) {
        return rBookCarService.queryPage(bookCarDto);
    }

    @ApiOperation(value = "详情")
    @GetMapping("/{id}")
    public ApiResult getById(@PathVariable("id") Long id) {
        return ApiResult.ok(rBookCarService.detail(id));
    }

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    public ApiResult save(@RequestBody RBookCar rBookCar) {
        return ApiResult.ok(rBookCarService.add(rBookCar));
    }

    @ApiOperation(value = "修改")
    @PostMapping("/edit")
    public ApiResult edit(@RequestBody RBookCar rBookCar) {
        return ApiResult.ok(rBookCarService.edit(rBookCar));
    }


    @ApiOperation(value = "删除")
    @PostMapping("/delete")
    public ApiResult removeById(@RequestBody Long[] ids) {
        return ApiResult.ok(rBookCarService.removeByIds(Arrays.asList(ids)));
    }

    @ApiOperation(value ="导出")
    @PostMapping("/export")
    public void export(@RequestBody BookCarDto dto, HttpServletResponse response) {
         rBookCarService.export(dto,response);
    }

}

